﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.ServiceLocation;

namespace UnityExtensions
{
    /// <summary>
    /// Defines the interface for the registry of region's content.
    /// </summary>
    /// <remarks>
    /// This interface is based on the <see cref="IRegionViewRegistry"/>, however provides additional contextual information about the region in which
    /// the content is being created.
    /// </remarks>
    public interface IScopedRegionViewRegistry
    {
        /// <summary>
        /// Event triggered when a content is registered to a region name.
        /// </summary>
        /// <remarks>
        /// This event uses weak references to the event handler to prevent this service (typically a singleton) of keeping the
        /// target element longer than expected. For security reasons, to use weak delegates in Silverlight you must provide
        /// a delegate that is available in the public API of the class (no private or anonymous delegates allowed).
        /// </remarks>
        event EventHandler<ViewRegisteredEventArgs> ContentRegistered;

        /// <summary>
        /// Returns a delegate that can be used to get the contents associated with a region.
        /// </summary>
        /// <param name="regionName">Region name for which contents are requested.</param>
        /// <returns>Collection of delegates used to resolve views associated with <paramref name="regionName" />.</returns>
        IEnumerable<Func<IRegion, IServiceLocator, object>> GetContents(string regionName);

        /// <summary>
        /// Registers a content type with a region name.
        /// </summary>
        /// <param name="regionName">Region name to which <paramref name="viewType" /> will be registered.</param>
        /// <param name="viewType">Content type to be registered for <paramref name="regionName" />.</param>
        void RegisterViewWithRegion(string regionName, Type viewType);

        /// <summary>
        /// Registers a delegate that can be used to retrieve the content associated with a region name. 
        /// </summary>
        /// <param name="regionName">Region name to which <paramref name="getContentDelegate" /> will be registered.</param>
        /// <param name="getContentDelegate">Delegate used to retrieve the content associated with <paramref name="regionName" />.</param>
        void RegisterViewWithRegion(string regionName, Func<IRegion, IServiceLocator, object> getContentDelegate);
    }
}
